import Router from 'koa-router';
import { 
  getTags, 
  getHotTags,
  getTagById, 
  getTagBySlug,
  createTag, 
  updateTag, 
  deleteTag,
  deleteTagsBatch,
  mergeTags,
  syncTagArticleCount
} from '../controllers/tag.controller';
import { authMiddleware } from '../middlewares/auth.middleware';
import { roleMiddleware } from '../middlewares/role.middleware';

const router = new Router();

/**
 * @route GET /api/tags
 * @desc 获取标签列表
 * @access Public
 */
router.get('/', getTags);

/**
 * @route GET /api/tags/hot
 * @desc 获取热门标签
 * @access Public
 */
router.get('/hot', getHotTags);

/**
 * @route GET /api/tags/:id
 * @desc 获取标签详情
 * @access Public
 */
router.get('/:id', getTagById);

/**
 * @route GET /api/tags/slug/:slug
 * @desc 根据Slug获取标签详情
 * @access Public
 */
router.get('/slug/:slug', getTagBySlug);

/**
 * @route POST /api/tags
 * @desc 创建标签
 * @access Private (需要管理员或编辑角色)
 */
router.post('/', authMiddleware, roleMiddleware(['admin', 'editor']), createTag);

/**
 * @route PUT /api/tags/:id
 * @desc 更新标签
 * @access Private (需要管理员或编辑角色)
 */
router.put('/:id', authMiddleware, roleMiddleware(['admin', 'editor']), updateTag);

/**
 * @route DELETE /api/tags/:id
 * @desc 删除标签
 * @access Private (需要管理员或编辑角色)
 */
router.delete('/:id', authMiddleware, roleMiddleware(['admin', 'editor']), deleteTag);

/**
 * @route POST /api/tags/batch/delete
 * @desc 批量删除标签
 * @access Private (需要管理员或编辑角色)
 */
router.post('/batch/delete', authMiddleware, roleMiddleware(['admin', 'editor']), deleteTagsBatch);

/**
 * @route POST /api/tags/merge
 * @desc 合并标签
 * @access Private (需要管理员或编辑角色)
 */
router.post('/merge', authMiddleware, roleMiddleware(['admin', 'editor']), mergeTags);

/**
 * @route POST /api/tags/:id/sync
 * @desc 同步标签文章数量
 * @access Private (需要管理员或编辑角色)
 */
router.post('/:id/sync', authMiddleware, roleMiddleware(['admin', 'editor']), syncTagArticleCount);

/**
 * @route POST /api/tags/sync
 * @desc 同步所有标签文章数量
 * @access Private (需要管理员或编辑角色)
 */
router.post('/sync', authMiddleware, roleMiddleware(['admin', 'editor']), syncTagArticleCount);

export default router; 